/**
 * 
 */
package x10.clients.tcpClient;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.net.Socket;
import java.net.UnknownHostException;

import x10.event.X10Event;

/**
 * @author Denny
 *
 */
public class TCPClient {

    public final static String SERVER_HOSTNAME = "localhost";
    public final static int COMM_PORT = 1010;

    private Socket socket;
    private X10Event device;
    
    public TCPClient(){

	try{
	    this.socket = new Socket(SERVER_HOSTNAME, COMM_PORT);
	    InputStream iStream = this.socket.getInputStream();
	    ObjectInputStream oiStream = new ObjectInputStream(iStream);
	    while(true){
		this.device = (X10Event) oiStream.readObject();
		System.out.println("RCVD:" + device.toString());
	    }

	} catch (UnknownHostException uhe){
	    System.out.println("Don't know about host: " + SERVER_HOSTNAME);

	} catch (IOException ioe){
	    System.out.println("Couldn't get IO for the connection to: " + SERVER_HOSTNAME + ":" + COMM_PORT);
		    
	} catch (ClassNotFoundException cnfe){
	    System.out.println("Wanted class X10Device, but got class " + cnfe);

	} catch (Exception e){
	    e.printStackTrace();
	}
    }
}

